//
//  MyFeaturesViewController.m
//  iPhoneKML
//
//  Created by Benjamin Blundell on 17/11/2009.
//  Copyright 2009 Section9. All rights reserved.
//

#import "MyFeaturesViewController.h"


@implementation MyFeaturesViewController

@synthesize tableMapData;
@synthesize	delegate;
@synthesize tableView;



- (void)viewWillAppear:(BOOL)animated {
	[self.tableView reloadData];
}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
	[self.tableMapData release];
}

#pragma mark -
#pragma mark Table Delegate Methods

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {

#ifdef DEBUG
	NSLog(@"%@",table);
#endif
	
	if (self.tableMapData){
		return [[self.tableMapData allKeys] count]; 
	}
	return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *MyMapTableIdentifier = @"MyMapTableIdentifier";
	UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier: MyMapTableIdentifier];
	
	if (cell == nil) { 
		cell = [[[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyMapTableIdentifier] autorelease];
	}
	
	cell.textLabel.text = [[self.tableMapData allKeys] objectAtIndex:indexPath.row];
	
	
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	NSUInteger row = [indexPath row];
	NSString *key = [[self.tableMapData allKeys] objectAtIndex:row];
	
	
#ifdef DEBUG
	NSLog(@"row %d with data %@",row,[self.tableMapData objectForKey:key ]);
#endif
	
	if (self.delegate){
		[self.delegate myFeaturesViewController:self didSelectFeature:key withData: [self.tableMapData objectForKey:key]];
	}
}


/*- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
 
 }*/





@end
